

/*****************************************************************
  the Flash Real Data are created in SystemConfigInitialData.s43
******************************************************************/
/////////////////////////////////////////////
// define Protection Mode for compiler
/////////////////////////////////////////////
#define _USE_ADG8_FOR_OC_PROTECTION_
//#define _USE_OPA_FOR_OC_PROTECTION_


///////////////////////////////////////////////////////////
// define Flash Segment Address (one segment = 128 bytes)
///////////////////////////////////////////////////////////
#define Flash_segment_Size 128  // bytes
#define Flash_segment_A   0x1980  //can not be written
#define Flash_segment_B   0x1900
#define Flash_segment_C   0x1880
#define Flash_segment_D   0x1800

#define Config_Segment   Flash_segment_C  //importment define

#define Calibration_Segment   Flash_segment_D
#define Calibration_Done      0x11
#define Calibration_UnDone    0xFF
//#define Calibration_Segment   Config_Segment + 0x70

#define Counting_Segment   Flash_segment_B  //importment define

//////////////////////////////////////////////////////////////////////////////////////
//  Define flash Data address offset (range: 0~112 bytes)
//  the offset order below is followed by SystemConfigInitialData.s43 data order
//////////////////////////////////////////////////////////////////////////////////////
#define ESS_Version_offset            0   // 2bytes
#define ESS_Serial_Num_offset         2   // 2bytes
#define ESS_Serial_Num_Extend_offset  4   // 2bytes
#define ESS_Manufacture_Date_offset   6   // 2bytes
#define ESS_Designed_Capacity_offset  8   // 2bytes
#define ESS_Designed_Voltage_offset   10  // 2bytes

#define SystemCurrentProtection_ReleaseTime_offset  12  // 2bytes
#define ADG8_SystemRefVol_mA_offset                 14  // 2bytes
#define ADG8_SystemOffDSGCurrentTh_mA_offset        16  // 2bytes
#define ADG8_SystemOffCHGCurrentTh_mA_offset        18  // 2bytes

#define OPA_SystemCurrentTh_mA_offset       20  // 2bytes

#define System_OV_Protection_offset 22  // 2bytes
#define System_OV_Recovery_offset   24  // 2bytes
#define System_UV_Recovery_offset   26  // 2bytes
#define System_UV_Protection_offset 28  // 2bytes

#define BalanceVoltageValue_offset   30  // 2bytes
#define BalancingTurnOnTime_offset   32  // 2bytes
#define BalancingDeltaVoltage_offset 34  // 2bytes
              
#define CycleCounts_Failure_Threshold_offset  36  // 2bytes
#define FCC_Failure_Threshold_offset          38  // 2bytes
#define FCC_MAX_Limit_offset                  40  // 2bytes
#define FCC_MIN_Limit_offset                  42  // 2bytes
#define FCC_Delta_Limit_offset                44  // 2bytes
#define Cell_Voltage_MAX_Limit_offset         46  // 2bytes
#define Cell_Voltage_MIN_Limit_offset         48  // 2bytes

#define ButtonPressTime_offset                50  // 2bytes

#define FC_TH_Voltage_High_offset             52  // 2bytes
#define FC_TH_Voltage_Low_offset              54  // 2bytes
#define FD_TH_Voltage_High_offset             56  // 2bytes
#define FD_TH_Voltage_Low_offset              58  // 2bytes
#define TCA_TH_Voltage_offset                 60  // 2bytes

#define ESS_ChargingCurrent_offset            62  // 2bytes
#define ESS_ChargingVoltage_offset            64  // 2bytes


#define PackConnectOnDeltaVoltageTH_offset    66  // 2bytes

#define CountingTimeBase_offset                 68  // 2bytes
#define ADG8_OverCurrentRecording_C1_mA_offset  70  // 2bytes  
#define ADG8_OverCurrentRecording_C2_mA_offset  72  // 2bytes

#define Pack_Voltage_MAX_Limit_offset      		74  // 2bytes
#define Pack_Voltage_MIN_Limit_offset       	76  // 2bytes

#define DSG_OC_Protection_Delay_Cycle_offset  78  // 1byte
#define CHG_OC_Protection_Delay_Cycle_offset  79  // 1byte
#define UV_Protection_Delay_Cycle_offset      80  // 1byte
#define OV_Protection_Delay_Cycle_offset      81  // 1byte
#define Balance_Protection_Delay_Cycle_offset 82  // 1byte

#define CHG_OT_Protection_Delay_Cycle_offset  83  // 1byte
#define DSG_OT_Protection_Delay_Cycle_offset  84  // 1byte
#define MosFET_Protection_Delay_Cycle_offset  85  // 1byte

#define CHG_Over_Temperature_Th_offset        86  // 2bytes
#define CHG_OT_Recovery_offset                88  // 2bytes
#define DSG_Over_Temperature_Th_offset        90  // 2bytes
#define DSG_OT_Recovery_offset                92  // 2bytes

#define Pack_Temperature_MAX_Limit_offset    94 // ; 2bytes
#define Pack_Temperature_MIN_Limit_offset    96 // ; 2bytes

#define Temperature_CelsiusToKelvin_Factor_offset    98 // ; 2bytes

#define Under_Temperature_Th_offset      		  100	  // ; 2bytes ; 
#define Under_Temperature_Recovery_offset      102	  // ; 2bytes ; 
#define UT_Protection_Delay_Cycle_offset       104   //Cycle ; 2byte



////////////////////////////////////////////////////////////
//  ESS System Information
////////////////////////////////////////////////////////////
#define ESS_Version             *((unsigned int *)(Config_Segment + ESS_Version_offset))
#define ESS_Serial_Num          *((unsigned int *)(Config_Segment + ESS_Serial_Num_offset))
#define ESS_Serial_Num_Extend   *((unsigned int *)(Config_Segment + ESS_Serial_Num_Extend_offset))
#define ESS_Manufacture_Date    *((unsigned int *)(Config_Segment + ESS_Manufacture_Date_offset))
#define ESS_Designed_Capacity   *((unsigned int *)(Config_Segment + ESS_Designed_Capacity_offset))
#define ESS_Designed_Voltage    *((unsigned int *)(Config_Segment + ESS_Designed_Voltage_offset))


///////////////////////////////////////////////////////////
//  AD8293G80
//  12-bit ADC internal ref = 2.5V
//  ADC external ref. voltage = 1.1V (ADC Value = 1833)
//  higher than 1.1V is in Discharging Status
//  lower than 1.1V is in Charging Status
//  positive for charge, negative for discharge.
//  1A ~= 38 ADC codes
//////////////////////////////////////////////////////////
// Over Current Protection
////////////////////////////////////////////////////////////
#define SystemCurrentProtection_ReleaseTime   *((unsigned int *)(Config_Segment + SystemCurrentProtection_ReleaseTime_offset))
#define ADG8_SystemRefVol_mA                 *((unsigned int *)(Config_Segment + ADG8_SystemRefVol_mA_offset))
#define ADG8_SystemOffDSGCurrentTh_mA        *((unsigned int *)(Config_Segment + ADG8_SystemOffDSGCurrentTh_mA_offset))
#define ADG8_SystemOffCHGCurrentTh_mA        *((unsigned int *)(Config_Segment + ADG8_SystemOffCHGCurrentTh_mA_offset))

//////////////////////////////////////////////////////////
// OPA2376, 
// gain : 140K/1K, getting current range 7.5A ~ -7.5A (for refrernce 2.5V ADC)
// 1A ~= 540 ADC codes, 0.5A ~= 270 ADC codes.
// getCHGCurrent() & getDSGCurrent();
//////////////////////////////////////////////////////////
#define OPA_SystemCurrentTh_mA  *((unsigned int *)(Config_Segment + OPA_SystemCurrentTh_mA_offset))

////////////////////////////////////////////////////////////
// Over Voltage Protection
////////////////////////////////////////////////////////////
#define System_OV_Protection  		*((unsigned int *)(Config_Segment + System_OV_Protection_offset))
#define System_OV_Recovery  			*((unsigned int *)(Config_Segment + System_OV_Recovery_offset))
#define System_UV_Recovery  			*((unsigned int *)(Config_Segment + System_UV_Recovery_offset))
#define System_UV_Protection  		*((unsigned int *)(Config_Segment + System_UV_Protection_offset)) 



////////////////////////////////////////////////////////////
// for balancing reference
////////////////////////////////////////////////////////////
#define BalanceVoltageValue    *((unsigned int *)(Config_Segment + BalanceVoltageValue_offset))
#define BalancingTurnOnTime    *((unsigned int *)(Config_Segment + BalancingTurnOnTime_offset))
#define BalancingDeltaVoltage  *((unsigned int *)(Config_Segment + BalancingDeltaVoltage_offset))


//////////////////////////////////////////////////////////
// Pack data for checking reading data whether valid or not 
//////////////////////////////////////////////////////////
#define CycleCounts_Failure_Threshold   *((unsigned int *)(Config_Segment + CycleCounts_Failure_Threshold_offset))
#define FCC_Failure_Threshold           *((unsigned int *)(Config_Segment + FCC_Failure_Threshold_offset))
#define FCC_MAX_Limit      		          *((unsigned int *)(Config_Segment + FCC_MAX_Limit_offset))
#define FCC_MIN_Limit      		          *((unsigned int *)(Config_Segment + FCC_MIN_Limit_offset))
#define FCC_Delta_Limit                 *((unsigned int *)(Config_Segment + FCC_Delta_Limit_offset))
#define Cell_Voltage_MAX_Limit      		*((unsigned int *)(Config_Segment + Cell_Voltage_MAX_Limit_offset))
#define Cell_Voltage_MIN_Limit      		*((unsigned int *)(Config_Segment + Cell_Voltage_MIN_Limit_offset))

////////////////////////////////////////////////////////////
// for Button
////////////////////////////////////////////////////////////////////////////
#define ButtonPressTime  *((unsigned int *)(Config_Segment + ButtonPressTime_offset))

////////////////////////////////////////////////////////////
// for User Module Status Indication
////////////////////////////////////////////////////////////
#define FC_TH_Voltage_High  *((unsigned int *)(Config_Segment + FC_TH_Voltage_High_offset))
#define FC_TH_Voltage_Low   *((unsigned int *)(Config_Segment + FC_TH_Voltage_Low_offset)) 
#define FD_TH_Voltage_High  *((unsigned int *)(Config_Segment + FD_TH_Voltage_High_offset))
#define FD_TH_Voltage_Low   *((unsigned int *)(Config_Segment + FD_TH_Voltage_Low_offset)) 
#define TCA_TH_Voltage      *((unsigned int *)(Config_Segment + TCA_TH_Voltage_offset))    

#define ESS_Designed_ChargingCurrent    *((unsigned int *)(Config_Segment + ESS_ChargingCurrent_offset))
#define ESS_Designed_ChargingVoltage    *((unsigned int *)(Config_Segment + ESS_ChargingVoltage_offset))

////////////////////////////////////////////////////////////
// for Pack Mos FET Control
////////////////////////////////////////////////////////////
#define PackConnectOnDeltaVoltageTH     *((unsigned int *)(Config_Segment + PackConnectOnDeltaVoltageTH_offset))

////////////////////////////////////////////////////////////
// for over current counting and define current range
////////////////////////////////////////////////////////////
#define CountingTimeBase                  *((unsigned int *)(Config_Segment + CountingTimeBase_offset))
#define ADG8_OverCurrentRecording_C1_mA   *((unsigned int *)(Config_Segment + ADG8_OverCurrentRecording_C1_mA_offset))
#define ADG8_OverCurrentRecording_C2_mA   *((unsigned int *)(Config_Segment + ADG8_OverCurrentRecording_C2_mA_offset))  

#define Pack_Voltage_MAX_Limit       		  *((unsigned int *)(Config_Segment + Pack_Voltage_MAX_Limit_offset))
#define Pack_Voltage_MIN_Limit       		  *((unsigned int *)(Config_Segment + Pack_Voltage_MIN_Limit_offset))


#define DSG_OC_Protection_Delay_Cycle     *((unsigned char *)(Config_Segment + DSG_OC_Protection_Delay_Cycle_offset))
#define CHG_OC_Protection_Delay_Cycle     *((unsigned char *)(Config_Segment + CHG_OC_Protection_Delay_Cycle_offset))
#define UV_Protection_Delay_Cycle         *((unsigned char *)(Config_Segment + UV_Protection_Delay_Cycle_offset))
#define OV_Protection_Delay_Cycle         *((unsigned char *)(Config_Segment + OV_Protection_Delay_Cycle_offset))
#define Balance_Protection_Delay_Cycle    *((unsigned char *)(Config_Segment + Balance_Protection_Delay_Cycle_offset))

#define CHG_OT_Protection_Delay_Cycle     *((unsigned char *)(Config_Segment + CHG_OT_Protection_Delay_Cycle_offset))
#define DSG_OT_Protection_Delay_Cycle     *((unsigned char *)(Config_Segment + DSG_OT_Protection_Delay_Cycle_offset))
#define MosFET_Protection_Delay_Cycle     *((unsigned char *)(Config_Segment + MosFET_Protection_Delay_Cycle_offset))

#define CHG_Over_Temperature_Th           *((unsigned int *)(Config_Segment + CHG_Over_Temperature_Th_offset))
#define CHG_OT_Recovery                   *((unsigned int *)(Config_Segment + CHG_OT_Recovery_offset))

#define DSG_Over_Temperature_Th           *((unsigned int *)(Config_Segment + DSG_Over_Temperature_Th_offset))
#define DSG_OT_Recovery                   *((unsigned int *)(Config_Segment + DSG_OT_Recovery_offset))

#define Pack_Temperature_MAX_Limit        *((unsigned int *)(Config_Segment + Pack_Temperature_MAX_Limit_offset))
#define Pack_Temperature_MIN_Limit        *((unsigned int *)(Config_Segment + Pack_Temperature_MIN_Limit_offset))

#define Temperature_CelsiusToKelvin_Factor   *((unsigned int *)(Config_Segment + Temperature_CelsiusToKelvin_Factor_offset))

#define Under_Temperature_Th              *((int *)(Config_Segment + Under_Temperature_Th_offset))
#define Under_Temperature_Recovery        *((int *)(Config_Segment + Under_Temperature_Recovery_offset))
#define UT_Protection_Delay_Cycle         *((unsigned int *)(Config_Segment + UT_Protection_Delay_Cycle_offset))



///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
//  Define Calibration Data address offset (range: 0~38 bytes)
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
#define		Calibration_Completion_Status_Offset   0 //; Calibration_UnDone    //1byte
#define		Calibration_Times_Offset               1 //; 1byte
#define		Cal_Date_Year_Offset                   2 //;_ESS_System_Initial_Date_Year_            //2bytes
#define		Cal_Date_Month_Offset                  4 //;_ESS_System_Initial_Date_Month_           //1byte
#define		Cal_Date_Day_Offset                    5 //;_ESS_System_Initial_Date_Day_             //1byte
#define		Cal_Date_24Hour_Offset                 6 //;_ESS_System_Initial_Date_Hour_24hSystem_  //1byte
#define		Cal_Date_Minute_Offset                 7 //;_ESS_System_Initial_Date_Minute_          //1byte

#define		Cal_Second_DSG_Current_mA_Offset       8 //; 6000mA ; 2bytes    
#define		Cal_Second_DSG_Current_ADG8_ADC_Offset 10//; 2000 ADC ; 2bytes  
#define		Cal_Second_DSG_Current_OPA_ADC_Offset  12//; 3900  ADC ; 2bytes

#define		Cal_First_DSG_Current_mA_Offset        14//; 1000mA ; 2bytes    
#define		Cal_First_DSG_Current_ADG8_ADC_Offset  16//; 1900 ADC ; 2bytes  
#define		Cal_First_DSG_Current_OPA_ADC_Offset   18//; 546  ADC ; 2bytes

#define		Cal_Zero_Current_mA_Offset             20//;  0mA ; 2bytes      
#define		Cal_Zero_Current_ADG8_ADC_Offset       22//; 1833 ADC ; 2bytes  
#define		Cal_Zero_Current_OPA_ADC_Offset        24//; 0  ADC ; 2bytes

#define		Cal_First_CHG_Current_mA_Offset        26//; 1000mA ; 2bytes    
#define		Cal_First_CHG_Current_ADG8_ADC_Offset  28//; 1700 ADC ; 2bytes  
#define		Cal_First_CHG_Current_OPA_ADC_Offset   30//; 546  ADC ; 2bytes

#define		Cal_Second_CHG_Current_mA_Offset       32//; 6000mA ; 2bytes    
#define		Cal_Second_CHG_Current_ADG8_ADC_Offset 34//; 1600 ADC ; 2bytes  
#define		Cal_Second_CHG_Current_OPA_ADC_Offset  36//; 3900  ADC ; 2bytes

#define   ADG8_System_DSG_RefVol_ADC_offset       38//; 2bytes
#define   ADG8_System_CHG_RefVol_ADC_offset       40//; 2bytes
#define   ADG8_SystemOffDSGCurrentTh_ADC_offset   42//; 2bytes
#define   ADG8_SystemOffCHGCurrentTh_ADC_offset   44//; 2bytes
              
#define   ADG8_System_DSG_Factor_offset           46//; float 4bytes
#define   ADG8_System_CHG_Factor_offset           50//; float 4bytes
              
#define   OPA_SystemDSGCurrentTh_ADC_offset       54//; 2bytes
#define   OPA_SystemCHGCurrentTh_ADC_offset       56//; 2bytes
#define   OPA_SystemDSGCurrentOffset_ADC_offset   58//; 2bytes
#define   OPA_SystemCHGCurrentOffset_ADC_offset   60//; 2bytes
#define   OPA_System_DSG_Factor_offset            62//; float 4bytes
#define   OPA_System_CHG_Factor_offset            66//; float 4bytes

/*
////////////////////////////////////////////////////////////
// for over current counting and define current range ADC
////////////////////////////////////////////////////////////
#define ADG8_OverCurrentRecording_C1_DSGADC_offset  70     	//2055 //(> 1.1V) ; 2bytes
#define ADG8_OverCurrentRecording_C1_CHGADC_offset  72     	//1517 //(< 1.1V) ; 2bytes
#define ADG8_OverCurrentRecording_C2_DSGADC_offset  74     	//2469 //(>1.1V) ; 2bytes
#define ADG8_OverCurrentRecording_C2_CHGADC_offset  76     	//1121 //(< 1.1V) ; 2bytes
*/

////////////////////////////////////////////////////////////
// reference define
////////////////////////////////////////////////////////////
#define	Calibration_Completion_Status     	*((unsigned char *)(Calibration_Segment + Calibration_Completion_Status_Offset  ))
#define	Calibration_Times                 	*((unsigned char *)(Calibration_Segment + Calibration_Times_Offset              ))
#define	Cal_Date_Year                     	*((unsigned int *)(Calibration_Segment + Cal_Date_Year_Offset                  ))
#define	Cal_Date_Month                    	*((unsigned char *)(Calibration_Segment + Cal_Date_Month_Offset                 ))
#define	Cal_Date_Day                      	*((unsigned char *)(Calibration_Segment + Cal_Date_Day_Offset                   ))
#define	Cal_Date_24Hour                   	*((unsigned char *)(Calibration_Segment + Cal_Date_24Hour_Offset                ))
#define	Cal_Date_Minute                   	*((unsigned char *)(Calibration_Segment + Cal_Date_Minute_Offset                ))

#define	Cal_Second_DSG_Current_mA         	*((unsigned int *)(Calibration_Segment + Cal_Second_DSG_Current_mA_Offset      ))
#define	Cal_Second_DSG_Current_ADG8_ADC   	*((unsigned int *)(Calibration_Segment + Cal_Second_DSG_Current_ADG8_ADC_Offset))
#define	Cal_Second_DSG_Current_OPA_ADC    	*((unsigned int *)(Calibration_Segment + Cal_Second_DSG_Current_OPA_ADC_Offset ))

#define	Cal_First_DSG_Current_mA          	*((unsigned int *)(Calibration_Segment + Cal_First_DSG_Current_mA_Offset       ))
#define	Cal_First_DSG_Current_ADG8_ADC    	*((unsigned int *)(Calibration_Segment + Cal_First_DSG_Current_ADG8_ADC_Offset ))
#define	Cal_First_DSG_Current_OPA_ADC     	*((unsigned int *)(Calibration_Segment + Cal_First_DSG_Current_OPA_ADC_Offset  ))

#define	Cal_Zero_Current_mA               	*((unsigned int *)(Calibration_Segment + Cal_Zero_Current_mA_Offset            ))
#define	Cal_Zero_Current_ADG8_ADC         	*((unsigned int *)(Calibration_Segment + Cal_Zero_Current_ADG8_ADC_Offset      ))
#define	Cal_Zero_Current_OPA_ADC          	*((unsigned int *)(Calibration_Segment + Cal_Zero_Current_OPA_ADC_Offset       ))

#define	Cal_First_CHG_Current_mA          	*((unsigned int *)(Calibration_Segment + Cal_First_CHG_Current_mA_Offset       ))
#define	Cal_First_CHG_Current_ADG8_ADC    	*((unsigned int *)(Calibration_Segment + Cal_First_CHG_Current_ADG8_ADC_Offset ))
#define	Cal_First_CHG_Current_OPA_ADC     	*((unsigned int *)(Calibration_Segment + Cal_First_CHG_Current_OPA_ADC_Offset  ))

#define	Cal_Second_CHG_Current_mA         	*((unsigned int *)(Calibration_Segment + Cal_Second_CHG_Current_mA_Offset      ))
#define	Cal_Second_CHG_Current_ADG8_ADC   	*((unsigned int *)(Calibration_Segment + Cal_Second_CHG_Current_ADG8_ADC_Offset))
#define	Cal_Second_CHG_Current_OPA_ADC    	*((unsigned int *)(Calibration_Segment + Cal_Second_CHG_Current_OPA_ADC_Offset ))

#define ADG8_System_DSG_RefVol_ADC            *((unsigned int *)(Calibration_Segment + ADG8_System_DSG_RefVol_ADC_offset))
#define ADG8_System_CHG_RefVol_ADC            *((unsigned int *)(Calibration_Segment + ADG8_System_CHG_RefVol_ADC_offset))

//////////////////////////////////////
// Over Current Protection Values
#define ADG8_SystemOffDSGCurrentTh_ADC        *((unsigned int *)(Calibration_Segment + ADG8_SystemOffDSGCurrentTh_ADC_offset))
#define ADG8_SystemOffCHGCurrentTh_ADC        *((unsigned int *)(Calibration_Segment + ADG8_SystemOffCHGCurrentTh_ADC_offset))

#define ADG8_System_DSG_Factor                *((float *)(Calibration_Segment + ADG8_System_DSG_Factor_offset))
#define ADG8_System_CHG_Factor                *((float *)(Calibration_Segment + ADG8_System_CHG_Factor_offset))

//////////////////////////////////////
// Current Detect Values
#define OPA_SystemDSGCurrentTh_ADC            *((unsigned int *)(Calibration_Segment + OPA_SystemDSGCurrentTh_ADC_offset))
#define OPA_SystemCHGCurrentTh_ADC            *((unsigned int *)(Calibration_Segment + OPA_SystemCHGCurrentTh_ADC_offset))

#define OPA_SystemDSGCurrentOffset_ADC        *((unsigned int *)(Calibration_Segment + OPA_SystemDSGCurrentOffset_ADC_offset))
#define OPA_SystemCHGCurrentOffset_ADC        *((unsigned int *)(Calibration_Segment + OPA_SystemCHGCurrentOffset_ADC_offset))
#define OPA_System_DSG_Factor                 *((float *)(Calibration_Segment + OPA_System_DSG_Factor_offset))
#define OPA_System_CHG_Factor                 *((float *)(Calibration_Segment + OPA_System_CHG_Factor_offset))

/*
////////////////////////////////////////////////////////////
// for over current counting and define current range ADC
#define ADG8_OverCurrentRecording_C1_DSGADC   *((unsigned int *)(Calibration_Segment + ADG8_OverCurrentRecording_C1_DSGADC_offset))
#define ADG8_OverCurrentRecording_C1_CHGADC   *((unsigned int *)(Calibration_Segment + ADG8_OverCurrentRecording_C1_CHGADC_offset))
#define ADG8_OverCurrentRecording_C2_DSGADC   *((unsigned int *)(Calibration_Segment + ADG8_OverCurrentRecording_C2_DSGADC_offset))
#define ADG8_OverCurrentRecording_C2_CHGADC   *((unsigned int *)(Calibration_Segment + ADG8_OverCurrentRecording_C2_CHGADC_offset))
*/


///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
//  ESS over current counting:  ORG     Flash_segment_B
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
#define CountingOverCurrent_C1C2_DSG_Offset    0	// counting range C1~C2			; 2byte
#define CountingOverCurrent_OverC2_DSG_Offset  2	// counting range  over C2		; 2byte
#define CountingOverCurrent_OCP_DSG_Offset     4	// counting range  occor OCP	; 2byte

#define CountingOverCurrent_C1C2_CHG_Offset    6	// counting range C1~C2			; 2byte
#define CountingOverCurrent_OverC2_CHG_Offset  8	// counting range  over C2		; 2byte
#define CountingOverCurrent_OCP_CHG_Offset     10	// counting range  occor OCP	; 2byte

////////////////////////////////////////////////////////////
// reference define
////////////////////////////////////////////////////////////
#define	CountingOverCurrent_C1C2_DSG    		*((unsigned int *)(Counting_Segment + CountingOverCurrent_C1C2_DSG_Offset ))
#define	CountingOverCurrent_OverC2_DSG    	*((unsigned int *)(Counting_Segment + CountingOverCurrent_OverC2_DSG_Offset ))
#define	CountingOverCurrent_OCP_DSG    			*((unsigned int *)(Counting_Segment + CountingOverCurrent_OCP_DSG_Offset ))

#define	CountingOverCurrent_C1C2_CHG    		*((unsigned int *)(Counting_Segment + CountingOverCurrent_C1C2_CHG_Offset ))
#define	CountingOverCurrent_OverC2_CHG    	*((unsigned int *)(Counting_Segment + CountingOverCurrent_OverC2_CHG_Offset ))
#define	CountingOverCurrent_OCP_CHG    			*((unsigned int *)(Counting_Segment + CountingOverCurrent_OCP_CHG_Offset ))



/************************************************
   Belowing vars are No Use
************************************************/
///////////////////////////////////////////////////////////
// System Temperture Protection ADC
//#define SystemTemperature_ADC_Hi  3000    // 80 C
//#define SystemTemperature_ADC_Lo  2000    // 75 C

///////////////////////////////////////////////////////////
// System Voltage Protection (read from Pack data)
//#define SystemVoltage_Hi  46800 //46.8V
//#define SystemVoltage_Lo  37200 //37.2V
//#define V_Fail_Band  3500 //3.5V

//////////////////////////////////////////////////////////
// Read Current From Packs data
//#define ModuleDischargeCurrentTh  -1000		//-1000mA
//#define ModuleChargeCurrentTh  		1000		//1000mA
